package com.haier.npt.exception;

import java.util.Locale;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

import com.haier.npt.utils.SpringUtil;
import com.haier.npt.utils.StringUtil;

public interface ExceptionResolvable {

	Integer getCode() ;
	
	String getMessage() ;

	default String getMessage(String message) {

		MessageSource messageSource =  SpringUtil.getBean(ReloadableResourceBundleMessageSource.class);
		Locale locale = LocaleContextHolder.getLocale();
		String localeMessage = messageSource.getMessage(message, null, "", locale);
		if(StringUtil.isEmpty(localeMessage)){
			localeMessage = message;
		}
		return localeMessage;
	}
}
